home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_CorrectItemList.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  2KB  |  98 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. **
  6. **  :ts=4
  7. */
  8.  
  9. #include "gtlayout_global.h"
  10.  
  11. #ifdef DO_MENUS
  12.  
  13.     /* LTP_CorrectItemList(RootMenu *Root,ItemNode *First,ItemNode *Last):
  14.      *
  15.      *    Chop nasty menus in two if they're too tall for this screen.
  16.      */
  17.  
  18. BOOLEAN __regargs
  19. LTP_CorrectItemList(RootMenu *Root,ItemNode *First,ItemNode *Last)
  20. {
  21.     ItemNode    *Item;
  22.     ULONG         Count = 0;
  23.     UWORD         Mask;
  24.     BOOLEAN         Overshoot = FALSE;
  25.  
  26.     Mask = First -> Flags & ITEMF_IsSub;
  27.  
  28.         // Count the number of items in this menu
  29.         // and check if there is one too many in it
  30.  
  31.     for(Item = First ; Item -> Node . mln_Succ ; Item = (ItemNode *)Item -> Node . mln_Succ)
  32.     {
  33.         if((Item -> Flags & ITEMF_IsSub) == Mask)
  34.         {
  35.             Count++;
  36.  
  37.             if(Item -> Top + Item -> Item . Height + 2 > Root -> Screen -> Height)
  38.                 Overshoot = TRUE;
  39.         }
  40.  
  41.         if(Item == Last)
  42.             break;
  43.     }
  44.  
  45.         // Did we scrape it?
  46.  
  47.     if(Overshoot && Count > 1)
  48.     {
  49.         ItemNode    *Here;
  50.         ULONG         i = (Count + 1) / 2;
  51.         WORD         Top,Left;
  52.  
  53.             // Find the median or whatever it's called in this part of the world
  54.  
  55.         for(Here = First ; i > 0 && Here -> Node . mln_Succ ; Here = (ItemNode *)Here -> Node . mln_Succ)
  56.         {
  57.             if((Here -> Flags & ITEMF_IsSub) == Mask)
  58.                 i--;
  59.         }
  60.  
  61.             // Shrink the two halves of the menu down to
  62.             // their minimum sizes
  63.  
  64.         LTP_ShrinkMenu(Root,First,(ItemNode *)Here -> Node . mln_Pred,Mask);
  65.         LTP_ShrinkMenu(Root,Here,Last,Mask);
  66.  
  67.             // Chop off the other half and stick it
  68.             // on at the right
  69.  
  70.         Left    = First -> Item . LeftEdge + First -> Item . Width + 2;
  71.         Top        = First -> Item . TopEdge;
  72.  
  73.             // Move the items over to the right
  74.  
  75.         for(;;)
  76.         {
  77.             if((Here -> Flags & ITEMF_IsSub) == Mask)
  78.             {
  79.                 Here -> Item . LeftEdge    = Left;
  80.                 Here -> Item . TopEdge    = Top;
  81.  
  82.                 Top += Here -> Item . Height;
  83.             }
  84.  
  85.             if(Here == Last)
  86.                 break;
  87.             else
  88.                 Here = (ItemNode *)Here -> Node . mln_Succ;
  89.         }
  90.  
  91.         return(TRUE);
  92.     }
  93.     else
  94.         return(FALSE);
  95. }
  96.  
  97. #endif    /* DO_MENUS */
  98.